package com.mcodesal.framework;



import android.content.Context;
import android.graphics.PixelFormat;
//import com.mcodesal.framework.GLSurfaceView;
import android.opengl.GLSurfaceView;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class GameView extends GLSurfaceView implements OnTouchListener {
	protected GameEngine mEngine;
	
	public GameView(Context context) {
		super(context);
		//Next two lines allow for transparent PNGs
		setEGLConfigChooser(8, 8, 8, 8, 0, 0);
        getHolder().setFormat(PixelFormat.RGBA_8888); 
        mEngine = new GameEngine(context);
        setRenderer(mEngine);
		setFocusable(true);
		setFocusableInTouchMode(true);
		this.setOnTouchListener(this);
	}

    @Override
	public boolean onTouch(View v, final MotionEvent event) {

    	queueEvent(new Runnable()
    	{
            public void run()
            {
        		mEngine.touchEvent(event);
            }
        });
    	// if this isn't here, multiple events happen on touch
    	try {
			Thread.sleep(20);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
        return true;

	}
    /**
     * Interface to pause engine updating
     */
    public void doPause() {
    	 mEngine.doPause();
    }
    /**
     * Interface to resume engine updating.
     */
    public void doResume() {
    	 mEngine.doResume();
    }
}